package com.example.area.io.netty.nio.buffer;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;

/**
 * @author kancy
 * @date 2019/2/23 16:54
 */
public class BufferDemo {

	public static void main(String[] args) {

		// 编码
		ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
		byteBuffer.put("A".getBytes()).put("B".getBytes());
		byteBuffer.flip();

		// 解码
		System.out.println(byteBuffer.toString());

		byte[] bytes = new byte[1];
		byteBuffer.get(bytes);
		System.out.println(new String(bytes));

		byteBuffer.get(bytes);
		System.out.println(new String(bytes));

		System.out.println(new String(byteBuffer.array()));

		byte[] newByte = Arrays.copyOf(byteBuffer.array(), byteBuffer.limit());
		System.out.println(new String(newByte));


	}
}
